package pattern.active;

import lombok.extern.slf4j.Slf4j;
import pattern.command.EatCommand;

import java.util.LinkedList;

/**
 * 小猪吃饭主动对象模式
 *
 * @author sun.ye
 * @since 2020-07-14 19:24
 */
@Slf4j
public class EatActiveObjectEngine {
    LinkedList<EatCommand> pigs = new LinkedList<>();

    public void addCommand(EatCommand pig){
        pigs.add(pig);
    }

    public void run(){
        while (!pigs.isEmpty()){
            EatCommand pig = pigs.getFirst();
            pigs.removeFirst();
            pig.eat();
            boolean isFull = pig.full();
            if (isFull){
                log.info("a pig is full");
            }else {
                pigs.add(pig);
            }
        }
        log.info("all pig are full");
    }


}